﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Meeting.DBUtility;
using Newtonsoft.Json;

namespace Meeting.BLL
{
    public  class MyMeeting
    {
        public string errorString = "";

        //我需要参加的会议
        public string GetMyMeeting(int pageIndex, int pageSize, string filter)
        {
            int nAllRecord = 0, nAllPages = 0;
            DataTable dt = DbHelperSQL.GetPage("a.Id", " b.Name,c.Name as Host,e.Name as Room,b.StartDate,b.EndDate,d.Name as Department,b.Status ",
                @" dbo.MeetingEmployee as a left join Meeting as b on a.MeetingId=b.Id left join Employee as c on b.HostId=c.Id
            left join Department as d on b.DepartmentId=d.Id left join Room as e on b.RoomId=e.Id", filter, " StartDate ",
                            pageIndex, pageSize, out nAllRecord, out nAllPages);
            if (dt == null) return "";
            Model.JsonGrid jr = new Model.JsonGrid();
            jr.total = nAllRecord;
            jr.rows = dt;

            Newtonsoft.Json.Converters.IsoDateTimeConverter timeConverter = new Newtonsoft.Json.Converters.IsoDateTimeConverter();
            timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm";

            return JsonConvert.SerializeObject(jr,timeConverter);
        }

        /// <summary>
        /// 我创建的会议
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public string GetAllMeeting(int pageIndex, int pageSize, string filter)
        {
            int nAllRecord = 0, nAllPages = 0;
            DataTable dt = DbHelperSQL.GetPage("Id", @"  *                                                       
                                                      ,Isnull((Select Name  from dbo.Room Where Id=RoomId),'') As RoomName
                                                      ,Isnull((Select Name  from dbo.MeetingCategory Where Id=CategoryId),'') As CategoryName", 
                                                     " dbo.Meeting ", filter, " CreateDate Desc ", pageIndex, pageSize, out nAllRecord, out nAllPages);
            if (dt == null) return "";
            Model.JsonGrid jr = new Model.JsonGrid();
            jr.total = nAllRecord;
            jr.rows = dt;
            Newtonsoft.Json.Converters.IsoDateTimeConverter timeConverter = new Newtonsoft.Json.Converters.IsoDateTimeConverter();
            timeConverter.DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm";
            return JsonConvert.SerializeObject(jr,timeConverter);
        }
    }
}
